import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {
    public static void main(String[] args) {
        String s = "111aaa222bbb";
        // 默认贪婪匹配
        // 贪婪：一直吃到**最后一个** b 之前
        Matcher g = Pattern.compile("(\\d+[a-z]+)b+").matcher(s);
        // 非贪婪：遇到第一个 b 就停
        Matcher r = Pattern.compile("(\\d+?[a-z]+?)b+").matcher(s);

        if (g.find())
            System.out.println("贪婪:   " + g.group(1)); // 111aaa222bb
        if (r.find())
            System.out.println("非贪婪: " + r.group(1)); // 111aaa
    }

}
